package com.hong.day03.activiti;

import org.activiti.engine.HistoryService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.TaskService;
import org.activiti.engine.history.HistoricActivityInstance;
import org.activiti.engine.history.HistoricActivityInstanceQuery;
import org.activiti.engine.task.Task;

import java.util.List;

/**
 * @Auther: csh
 * @Date: 2019/11/19 19:41
 * @Description:查询历史记录
 */
public class HistoryQuery {
    public static void main(String[] args) {
        //1.得到ProcessEngine对象
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        //2.得到HistoryService
        HistoryService historyService = processEngine.getHistoryService();
        //3.得到HistoryActivitiInstanceQuery对象
        HistoricActivityInstanceQuery historicActivityInstanceQuery = historyService.createHistoricActivityInstanceQuery();
        HistoricActivityInstanceQuery instanceQuery = historicActivityInstanceQuery.processInstanceId("5001");
        //4.执行查询 设置流程实例id
        List <HistoricActivityInstance> list = instanceQuery.orderByHistoricActivityInstanceStartTime().asc().list();
        //5.遍历查询结果
        for (HistoricActivityInstance historicActivityInstance : list) {
            System.out.println(historicActivityInstance.getActivityId());
            System.out.println(historicActivityInstance.getActivityName());
            System.out.println(historicActivityInstance.getProcessDefinitionId());
            System.out.println(historicActivityInstance.getProcessInstanceId());
            System.out.println("==============================");
        }

    }
}
